Count word frequency in a sentence in python
272
24-Apr-2025
Updated on 24-Apr-2025
Anubhav Kumar
24-Apr-2025Problem Statement
Given a sentence like:
You need to return:
Approach
Solution in Python
Explanation
sentence.lower(): Ensures "Hello" and "hello" are treated as the same.sentence.split(): Splits on whitespace by default.word_countstores each word as a key and its count as a value.Output: